Socket
Socket
Sign inDemoInstall

@messageformat/parser

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@messageformat/parser

An AST parser for ICU MessageFormat strings


Version published
Weekly downloads
567K
decreased by-2.59%
Maintainers
1
Weekly downloads
 
Created

What is @messageformat/parser?

@messageformat/parser is a library for parsing ICU MessageFormat strings. It allows developers to handle complex internationalization (i18n) scenarios by parsing and formatting messages with pluralization, gender, and other language-specific rules.

What are @messageformat/parser's main functionalities?

Parsing MessageFormat strings

This feature allows you to parse a MessageFormat string into an abstract syntax tree (AST). The example demonstrates parsing a message that handles pluralization based on the count.

const { parse } = require('@messageformat/parser');
const message = 'You have {count, plural, one {# message} other {# messages}}.';
const parsed = parse(message);
console.log(JSON.stringify(parsed, null, 2));

Handling nested messages

This feature allows you to parse messages with nested structures, such as gender-based selection combined with pluralization. The example demonstrates parsing a message that handles both gender and pluralization.

const { parse } = require('@messageformat/parser');
const message = '{gender, select, male {He} female {She} other {They}} liked {count, plural, one {# message} other {# messages}}.';
const parsed = parse(message);
console.log(JSON.stringify(parsed, null, 2));

Custom formatting

This feature allows you to parse messages with custom formatting options, such as currency formatting. The example demonstrates parsing a message that formats a number as a currency.

const { parse } = require('@messageformat/parser');
const message = 'The price is {price, number, ::currency/USD}.';
const parsed = parse(message);
console.log(JSON.stringify(parsed, null, 2));

Other packages similar to @messageformat/parser

Keywords

FAQs

Package last updated on 08 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc